package com.dylan.shot.common.util;

import org.apache.ibatis.mapping.MappedStatement;
import tk.mybatis.mapper.entity.EntityColumn;
import tk.mybatis.mapper.mapperhelper.EntityHelper;
import tk.mybatis.mapper.mapperhelper.MapperHelper;
import tk.mybatis.mapper.mapperhelper.MapperTemplate;
import tk.mybatis.mapper.mapperhelper.SqlHelper;

import java.util.Set;

/**
 * Created by Dylan on 2017/9/6.
 */
public class InsertSelectiveUseGeneratedKeysProvider extends MapperTemplate {

    public InsertSelectiveUseGeneratedKeysProvider(Class<?> mapperClass, MapperHelper mapperHelper) {
        super(mapperClass, mapperHelper);
    }

    /**
     * 插入，主键id，自增
     *
     * @param ms
     */
    public String insertSelectiveUseGeneratedKeys(MappedStatement ms) {
        final Class<?> entityClass = getEntityClass(ms);
        //开始拼sql
        StringBuilder sql = new StringBuilder();
        sql.append(SqlHelper.insertIntoTable(entityClass, tableName(entityClass)));
        sql.append(SqlHelper.insertColumns(entityClass, true, true, false));
        sql.append(SqlHelper.insertValuesColumns(entityClass, true, true, false));
        return sql.toString();
    }
}
